<template>
  <div class="login-container">
    <div class="login-card">
      <div class="login-title">
        <h2>Login</h2>
      </div>
      <el-form :inline="true" :model="form">
        <el-form-item label="Username">
          <el-input v-model="form.username" placeholder="Enter username"></el-input>
        </el-form-item>
        <el-form-item label="Password">
          <el-input v-model="form.password" type="password" placeholder="Enter password"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleLogin" :loading="loading">Login</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue'
import { loginApi } from '@/apis/login'
import { ElMessage } from 'element-plus'
import { useRouter } from 'vue-router'

const form = reactive({
  username: '',
  password: ''
})
const loading = ref(false)
const router = useRouter()

const handleLogin = async () => {
  if (!form.username || !form.password) {
    ElMessage.warning('请输入用户名和密码')
    return
  }
  loading.value = true
  try {
    const res = await loginApi(form)
    if (res && res.code === 1 &&res.data.token) {
      if (res.data.token) {
        localStorage.setItem('token', res.data.token)
      }
      ElMessage.success('登录成功')
      router.push('/admin')
    } else {
      ElMessage.error(res?.msg || '登录失败')
    }
  } catch (e) {
    ElMessage.error('登录请求异常')
  } finally {
    loading.value = false
  }
}
</script>

<style scoped>
.login-container {
  min-height: 100vh;
  width: 100vw;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}
.login-container::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
  background: url('/src/assets/002.png') center center/cover no-repeat;
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center;
  filter: brightness(0.85);
}
.login-card {
  width: 350px;
  padding: 30px 20px 20px 20px;
  box-shadow: 0 8px 32px rgba(255, 255, 255, 0.18);
  border-radius: 24px;
  background: rgba(232, 118, 118, 0.33); /* 更透明 */
  position: relative;
  z-index: 1;
  backdrop-filter: blur(2px);
}
.login-title {
  text-align: center;
  margin-bottom: 24px;
  color: #f54949;
  font-weight: bold;
}
</style>
<style>
html, body {
  overflow: hidden !important;
}
</style> 